jQuery(document).ready(function() {
	$(".select_amount").attr("disabled", true);
	
	$(".select_meal").change(function() {
		var price = parseFloat($(this).parent().parent().find(".mealPrice").text()
				.replace(',', '.'));
		var currentPrice = parseFloat($("#priceValue").text().replace(',', '.'));
		var amount = $(this).parent().parent().find('.select_amount');
		if ($(this).attr("checked")) {
			$("#priceValue").text((currentPrice + parseFloat(price))
					.toFixed(2));
			$(this).data('amount', 1);
			amount.removeAttr("disabled");
			amount.val("1");
		} else {
			$("#priceValue").text((currentPrice - parseFloat(price) * parseFloat(amount.val()))
					.toFixed(2));
		    $(this).data("amount", 0);
			amount.attr("disabled", true);
			amount.val("");
		};
	});
	$(".select_amount").change(function() {
		var price = parseFloat($(this).parent().parent().find(".mealPrice").text()
				.replace(',', '.'));
		var currentPrice = parseFloat($("#priceValue").text().replace(',', '.'));
		var amount = parseFloat($(this).val());
		var checkbox = $(this).parent().parent().find("input[type=checkbox]");
		var new_price = (currentPrice - price * checkbox.data('amount') 
				+ price * parseFloat($(this).val())).toFixed(2);
	    checkbox.data('amount', amount);
	    $("#priceValue").text(new_price);
		
	});
	$(".select_amount").keypress(function(e) {
		if (e.which == 13) {
		e.preventDefault();
		$(this).change();
		}
	});
});
